package com.yqkj.zysoft.upms.controller;


import  com.project.easy.common.util.collection.CollectionUtil;
import  com.project.easy.common.util.constants.SysModelConstant;
import  com.project.easy.common.util.constants.VersionConstant;
import  com.project.easy.common.util.dto.IdApiContextParam;
import  com.project.easy.common.util.dto.OneLongApiContextParam;
import  com.project.easy.common.util.dto.PageResDto;
import  com.project.easy.common.util.dto.R;
import  com.project.easy.common.util.dto.TwoApiContextParam;
import com.project.easy.common.framework.web.annotation.ApiValidator;
import com.project.easy.common.log.annotation.Logging;
import com.project.easy.common.framework.web.controller.BaseController;

import com.yqkj.zysoft.upms.entity.FrameworkGroup;
import com.yqkj.zysoft.upms.entity.dto.FrameWorkGroupAddRequest;
import com.yqkj.zysoft.upms.entity.dto.FrameWorkGroupUpdateRequest;
import com.yqkj.zysoft.upms.entity.dto.PageGroupRequest;
import com.yqkj.zysoft.upms.service.IFrameworkGroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 组 前端控制器
 * </p>
 *
 * @author GreatorMan.cool
 * @since 2022-08-10
 */
@RestController
@RequestMapping("/api/" + VersionConstant.ONE + "/upms/group")
public class FrameworkGroupController extends BaseController {

    @Autowired
    private IFrameworkGroupService frameworkGroupService;

    /**
     * 更新组权限
     * @param twoApiContextParam 公参数
     * @return 返回 true 成功
     */
    @PostMapping("/updateGroupConfigAuth")
    @Logging(value = SysModelConstant.UPMS)
    @ApiValidator
    public R<Boolean> updateGroupConfigAuth(@RequestBody TwoApiContextParam twoApiContextParam) {
        return R.success(frameworkGroupService.updateGroupConfigAuth(twoApiContextParam.getOne(), Long.valueOf(twoApiContextParam.getTwo())));
    }
    /**
     * 获取组权限
     * @param oneLongApiContextParam 公参数
     * @return 返回权限集合
     */
    @PostMapping("/getGroupConfigAuth")
    @Logging(value = SysModelConstant.UPMS)
    @ApiValidator
    public R<String> getGroupConfigAuth(@RequestBody OneLongApiContextParam oneLongApiContextParam) {
        return R.success(frameworkGroupService.getGroupConfigAuth(oneLongApiContextParam.getKey()));
    }
    /**
     * 新增
     * @param frameWorkGroupAddRequest 参数
     * @return 返回数据
     */
    @PostMapping("/add")
    @Logging(value = SysModelConstant.UPMS)
    @ApiValidator
    public R<Long> add(@RequestBody FrameWorkGroupAddRequest frameWorkGroupAddRequest) {
        return R.success(frameworkGroupService.add(frameWorkGroupAddRequest));
    }
    /**
     * 修改
     * @param frameWorkGroupUpdateRequest 参数
     * @return 返回数据
     */
    @PostMapping("/udpate")
    @Logging(value = SysModelConstant.UPMS)
    @ApiValidator
    public R<Boolean> udpate(@RequestBody FrameWorkGroupUpdateRequest frameWorkGroupUpdateRequest) {
        return R.success(frameworkGroupService.updateObject(frameWorkGroupUpdateRequest));
    }
    /**
     * 列表
     * @param pageGroupRequest 参数
     * @return 返回数据
     */
    @PostMapping("/pageList")
    @Logging(value = SysModelConstant.UPMS)
    @ApiValidator
    public R<PageResDto<FrameworkGroup>> pageList(@RequestBody PageGroupRequest pageGroupRequest) {
        return R.success(frameworkGroupService.pageList(pageGroupRequest));
    }
    /**
     * 验证编码
     * @param groupUpdateRequest 参数
     * @return 返回数据
     */
    @PostMapping("/verifyCode")
    @Logging(value = SysModelConstant.UPMS)
    @ApiValidator
    public R<Boolean> verifyCode(@RequestBody FrameWorkGroupUpdateRequest groupUpdateRequest) {
        return R.success(frameworkGroupService.verifyCode(groupUpdateRequest));
    }
    /**
     * 删除
     * @param sysParamDto 参数
     * @return 返回数据
     */
    @PostMapping("/del")
    @Logging(value = SysModelConstant.UPMS)
    @ApiValidator
    public R<Boolean> del(@RequestBody IdApiContextParam sysParamDto) {
        return R.success(this.del(frameworkGroupService, v -> v::setHasDel,
                CollectionUtil.parseIds(sysParamDto.getIds())));
    }
    /**
     * 禁用
     * @param oneApiContextParam 参数
     * @return 返回数据
     */
    @PostMapping("/disAble")
    @Logging(value = SysModelConstant.UPMS)
    @ApiValidator
    public R<Boolean> disAble(@RequestBody OneLongApiContextParam oneApiContextParam) {
        return R.success(this.frameworkGroupService.disAble(oneApiContextParam.getKey()));
    }
    /**
     * 启用
     * @param oneApiContextParam 参数
     * @return 返回数据
     */
    @PostMapping("/able")
    @Logging(value = SysModelConstant.UPMS)
    @ApiValidator
    public R<Boolean> able(@RequestBody OneLongApiContextParam oneApiContextParam) {
        return R.success(this.frameworkGroupService.able(oneApiContextParam.getKey()));
    }

}
